import time

from base_config import HOST
from pages.base_page import BasePage
from pages.elements import Elements
from pages.prodct_list_page import ProductListPage
from pages.product_detail_page import ProductDetailPage
from pages.release_page import ReleasePage
from pages.user_center_page import UserCenterPage
from utils.log_manager import my_logger
# 登录成功后的主页
class LoginSuccessPage(BasePage):
    url = HOST + 'index'
    # 打开首页
    def open_page(self):
        print("打开首页,",self.driver.current_url,self.url)
        self.open(self.url)

    # 去发布
    def go_to_release(self):
        self.click_element(Elements.FABU_BTN)
        return ReleasePage()

    # 搜商品
    def search(self,keyword):
        self.input_data(Elements.SEARCH_INPUT, keyword)
        self.click_element(Elements.SEARCH_BTN)
        # 搜索完返回的是商品列表的页面
        return ProductListPage()

    def search_success(self,keyword):
        time.sleep(3)
        try:
            current_url = self.driver.current_url
            my_logger.logger.info("查询商品后地址:{}", current_url)
            # http://127.0.0.1:9000/#/search?searchValue=%E6%B0%B4
            if 'searchValue' in current_url:
                return True
        except:
            return False
        return False

    '''
    选择第一个物品
    '''
    def click_first_product(self):
        my_logger.logger.debug("点击第一个元素1:{}",self.driver.current_url)
        self.click_element(Elements.FIRST_PRODUCT)
        return ProductDetailPage()
    '''
    到用户中心
    '''
    def go_to_user_center(self):
        self.click_element(Elements.NICK_NAME_ELE)
        self.sleep()
        self.click_element(Elements.MEMBER_INFO_LI)
        self.sleep(3)
        return UserCenterPage()



